package com.example.night.controller;

import com.example.night.data.SellingGood.SellingGoodPackage;
import com.example.night.service.ApiService.SellingGoodsService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/sellingGoods")
public class SellingGoodsController {
    private final SellingGoodsService sellingGoodsService;

    public SellingGoodsController(SellingGoodsService sellingGoodsService) {
        this.sellingGoodsService = sellingGoodsService;
    }

    @GetMapping("/get_sellingGoods_ranking")
    public Map<String, Object> fetchGoods(
            @RequestParam String start_date,
            @RequestParam String end_date,
            @RequestParam int page
    ) {
        List<SellingGoodPackage> sellingGoods = sellingGoodsService.fetchGoods(start_date, end_date, page);
        return Map.of(
                "total_goods", sellingGoods.size(),
                "goods", sellingGoods,
                "success", true
        );
    }
}
